package com.canbot.u05.utils;

import android.widget.ImageView;

import com.canbot.u05.MainApplication;

/**
 * 异步加载本地图片工具类
 * Created by tao.liu on 2017/5/23.
 */

public class LoadLocalImageUtil {

        private LoadLocalImageUtil() {
        }


        private static LoadLocalImageUtil instance = null;


        public static synchronized LoadLocalImageUtil getInstance() {
                if (instance == null) {
                        instance = new LoadLocalImageUtil();
                }
                return instance;
        }

        /**
         * 从内存卡中异步加载本地图片
         *
         * @param uri
         * @param imageView
         */
        public void displayFromSDCard(String uri, ImageView imageView) {
                // String imageUri = "file:///mnt/sdcard/image.png"; // from SD card
                MainApplication.instance.displayImage("file://" + uri, imageView);
        }


        /**
         * 从assets文件夹中异步加载图片
         *
         * @param imageName 图片名称，带后缀的，例如：1.png
         * @param imageView
         */
        public void dispalyFromAssets(String imageName, ImageView imageView) {
                // String imageUri = "assets://image.png"; // from assets
                MainApplication.instance.displayImage("assets://" + imageName,
                        imageView);
        }


        /**
         * 从drawable中异步加载本地图片
         *
         * @param imageId
         * @param imageView
         */
        public void displayFromDrawable(int imageId, ImageView imageView) {
                // String imageUri = "drawable://" + R.drawable.image; // from drawables
                // (only images, non-9patch)
                MainApplication.instance.displayImage("drawable://" + imageId,
                        imageView);
        }


        /**
         * 从内容提提供者中抓取图片
         */
        public void displayFromContent(String uri, ImageView imageView) {
                // String imageUri = "content://media/external/audio/albumart/13"; //
                // from content provider
                MainApplication.instance.displayImage("content://" + uri, imageView);
        }
}
